<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->

<!-- Mirrored from minetest.gitlab.io/minetest/spatial-vectors/ by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 01 Oct 2020 14:46:34 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Spatial Vectors - Minetest API Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../css/theme.css" />
  <link rel="stylesheet" href="../css/theme_extra.css" />
  <link href="../css/code_styles.css" rel="stylesheet" />
  <link href="../css/extra.css" rel="stylesheet" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "Spatial Vectors";
    var mkdocs_page_input_path = "spatial-vectors.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="../index.html" class="icon icon-home"> Minetest API Documentation</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="http://minetest.gitlab.io/minetest/search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../index.html">Home</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../games/index.html">Games</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../mods/index.html">Mods</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../aliases/index.html">Aliases</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../textures/index.html">Textures</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../sounds/index.html">Sounds</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../registered-definitions/index.html">Registered definitions</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../nodes/index.html">Nodes</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../map-terminology-and-coordinates/index.html">Map terminology and coordinates</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../hud/index.html">HUD</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../representations-of-simple-things/index.html">Representations of simple things</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../flag-specifier-format/index.html">Flag Specifier Format</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../items/index.html">Items</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../groups/index.html">Groups</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Tools</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../entity-damage-mechanism/index.html">Entity damage mechanism</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../metadata/index.html">Metadata</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../formspec/index.html">Formspec</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../inventory/index.html">Inventory</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../colors/index.html">Colors</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../escape-sequences/index.html">Escape sequences</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="index.html">Spatial Vectors</a>
    <ul class="current">
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../helper-functions/index.html">Helper functions</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../translations/index.html">Translations</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../perlin-noise/index.html">Perlin noise</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../ores/index.html">Ores</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../decoration-types/index.html">Decoration types</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../schematics/index.html">Schematics</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../lua-voxel-manipulator/index.html">Lua Voxel Manipulator</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../mapgen-objects/index.html">Mapgen objects</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../registered-entities/index.html">Registered entities</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../l-system-trees/index.html">L-system trees</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../minetest-namespace-reference/index.html">'minetest' namespace reference</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../class-reference/index.html">Class reference</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../definition-tables/index.html">Definition tables</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Minetest API Documentation</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
    
      
    
    <li>Spatial Vectors</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="spatial-vectors">Spatial Vectors<a class="headerlink" href="#spatial-vectors" title="Permanent link">&para;</a></h1>
<p>A spatial vector is similar to a position, but instead using
absolute world coordinates, it uses <em>relative</em> coordinates, relative to
no particular point.</p>
<p>Internally, it is implemented as a table with the 3 fields
<code>x</code>, <code>y</code> and <code>z</code>. Example: <code>{x = 0, y = 1, z = 0}</code>.</p>
<p>For the following functions, <code>v</code>, <code>v1</code>, <code>v2</code> are vectors,
<code>p1</code>, <code>p2</code> are positions,
<code>s</code> is a scalar (a number):</p>
<ul>
<li><code>vector.new(a[, b, c])</code>:<ul>
<li>Returns a vector.</li>
<li>A copy of <code>a</code> if <code>a</code> is a vector.</li>
<li><code>{x = a, y = b, z = c}</code>, if all of <code>a</code>, <code>b</code>, <code>c</code> are defined numbers.</li>
</ul>
</li>
<li><code>vector.direction(p1, p2)</code>:<ul>
<li>Returns a vector of length 1 with direction <code>p1</code> to <code>p2</code>.</li>
<li>If <code>p1</code> and <code>p2</code> are identical, returns <code>{x = 0, y = 0, z = 0}</code>.</li>
</ul>
</li>
<li><code>vector.distance(p1, p2)</code>:<ul>
<li>Returns zero or a positive number, the distance between <code>p1</code> and <code>p2</code>.</li>
</ul>
</li>
<li><code>vector.length(v)</code>:<ul>
<li>Returns zero or a positive number, the length of vector <code>v</code>.</li>
</ul>
</li>
<li><code>vector.normalize(v)</code>:<ul>
<li>Returns a vector of length 1 with direction of vector <code>v</code>.</li>
<li>If <code>v</code> has zero length, returns <code>{x = 0, y = 0, z = 0}</code>.</li>
</ul>
</li>
<li><code>vector.floor(v)</code>:<ul>
<li>Returns a vector, each dimension rounded down.</li>
</ul>
</li>
<li><code>vector.round(v)</code>:<ul>
<li>Returns a vector, each dimension rounded to nearest integer.</li>
</ul>
</li>
<li><code>vector.apply(v, func)</code>:<ul>
<li>Returns a vector where the function <code>func</code> has been applied to each
  component.</li>
</ul>
</li>
<li><code>vector.equals(v1, v2)</code>:<ul>
<li>Returns a boolean, <code>true</code> if the vectors are identical.</li>
</ul>
</li>
<li><code>vector.sort(v1, v2)</code>:<ul>
<li>Returns in order minp, maxp vectors of the cuboid defined by <code>v1</code>, <code>v2</code>.</li>
</ul>
</li>
<li><code>vector.angle(v1, v2)</code>:<ul>
<li>Returns the angle between <code>v1</code> and <code>v2</code> in radians.</li>
</ul>
</li>
<li><code>vector.dot(v1, v2)</code>:<ul>
<li>Returns the dot product of <code>v1</code> and <code>v2</code>.</li>
</ul>
</li>
<li><code>vector.cross(v1, v2)</code>:<ul>
<li>Returns the cross product of <code>v1</code> and <code>v2</code>.</li>
</ul>
</li>
<li><code>vector.offset(v, x, y, z)</code>:<ul>
<li>Returns the sum of the vectors <code>v</code> and <code>{x = x, y = y, z = z}</code>.</li>
</ul>
</li>
</ul>
<p>For the following functions <code>x</code> can be either a vector or a number:</p>
<ul>
<li><code>vector.add(v, x)</code>:<ul>
<li>Returns a vector.</li>
<li>If <code>x</code> is a vector: Returns the sum of <code>v</code> and <code>x</code>.</li>
<li>If <code>x</code> is a number: Adds <code>x</code> to each component of <code>v</code>.</li>
</ul>
</li>
<li><code>vector.subtract(v, x)</code>:<ul>
<li>Returns a vector.</li>
<li>If <code>x</code> is a vector: Returns the difference of <code>v</code> subtracted by <code>x</code>.</li>
<li>If <code>x</code> is a number: Subtracts <code>x</code> from each component of <code>v</code>.</li>
</ul>
</li>
<li><code>vector.multiply(v, s)</code>:<ul>
<li>Returns a scaled vector.</li>
<li>Deprecated: If <code>s</code> is a vector: Returns the Schur product.</li>
</ul>
</li>
<li><code>vector.divide(v, s)</code>:<ul>
<li>Returns a scaled vector.</li>
<li>Deprecated: If <code>s</code> is a vector: Returns the Schur quotient.</li>
</ul>
</li>
</ul>
<p>For the following functions <code>a</code> is an angle in radians and <code>r</code> is a rotation
vector ({x = <pitch>, y = <yaw>, z = <roll>}) where pitch, yaw and roll are
angles in radians.</p>
<ul>
<li><code>vector.rotate(v, r)</code>:<ul>
<li>Applies the rotation <code>r</code> to <code>v</code> and returns the result.</li>
<li><code>vector.rotate({x = 0, y = 0, z = 1}, r)</code> and
  <code>vector.rotate({x = 0, y = 1, z = 0}, r)</code> return vectors pointing
  forward and up relative to an entity's rotation <code>r</code>.</li>
</ul>
</li>
<li><code>vector.rotate_around_axis(v1, v2, a)</code>:<ul>
<li>Returns <code>v1</code> rotated around axis <code>v2</code> by <code>a</code> radians according to
  the right hand rule.</li>
</ul>
</li>
<li><code>vector.dir_to_rotation(direction[, up])</code>:<ul>
<li>Returns a rotation vector for <code>direction</code> pointing forward using <code>up</code>
  as the up vector.</li>
<li>If <code>up</code> is omitted, the roll of the returned vector defaults to zero.</li>
<li>Otherwise <code>direction</code> and <code>up</code> need to be vectors in a 90 degree angle to each other.</li>
</ul>
</li>
</ul>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../helper-functions/index.html" class="btn btn-neutral float-right" title="Helper functions">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../escape-sequences/index.html" class="btn btn-neutral" title="Escape sequences"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org/">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../escape-sequences/index.html" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../helper-functions/index.html" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '../index.html';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>

<!-- Mirrored from minetest.gitlab.io/minetest/spatial-vectors/ by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 01 Oct 2020 14:46:34 GMT -->
</html>
